package com.sanglh.tutorial.androidtouch;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.sanglh.tutorial.R;

public class DummyActivity extends Activity {
	public static final String ACTION_ADD_DEVICE = "ACTION_ADD_DEVICE";

	public static void requestAddDevice(Context context) {
		Intent intent = new Intent(context, DummyActivity.class);
		intent.setAction(ACTION_ADD_DEVICE);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_dummy);
		String action = getIntent().getAction();
		if (ACTION_ADD_DEVICE.equals(action)) {
			requestAddDevice();
		}
	}

	private void requestAddDevice() {
		ComponentName compName = new ComponentName(getApplicationContext(),
				DeviceReceiver.class);
		Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
		intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
		intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
				"Enable this feature to make you easily lock your screen");
		startActivityForResult(intent, 0);

	}

}
